package models

import "blog_api/db"

type Set struct {
	Id         int    `gorm:"column(id)" json:"id"`
	Key        string `gorm:"column(key)" json:"key"`
	Value      string `gorm:"column(value)" json:"value"`
	Status     int    `gorm:"column(status)" json:"status"`
	Remark     string `gorm:"column(remark)" json:"remark"`
	CreateTime uint64 `gorm:"column(create_time)" json:"create_time"`
	UpdateTime uint64 `gorm:"column(update_time)" json:"update_time"`
}

func (*Set) TableName() string {
	return "blog_set"
}

func AdminSetList(limit, offset int, field, keyword string) ([]Set, int64) {
	var s []Set
	var c int64
	l := db.Mysql.Model(&Set{})
	if keyword != "" {
		ids, err := db.SearchKeyword(keyword, ES_SET_INDEX)
		if err != nil {
			return s, 0
		}
		l.Where("id in (?)", ids)
	}
	l.Count(&c)
	l.Select(field).Order("create_time desc").Limit(limit).Offset(offset).Scan(&s)
	return s, c
}